

package com.iyouqu.dycm.search.utils.redis;


import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;


public class RedisSentinelPoolHolder {
  private RedisSentinelPoolHolder() {
  }
  
  private static class PoolHoledr {
    // private static redis.clients.util.Pool pool;
    private static CustomPool customPool;
    
    static {
      
      int maxIdle = Integer.parseInt(PropUtil.getProperty("search.redis.maxidle", "50")); // 最大空闲连接数
      int maxTotal = Integer.parseInt(PropUtil.getProperty("search.redis.maxtotal", "300")); // 最大连接数
      int maxWaitMillis = Integer.parseInt(PropUtil.getProperty("search.redis.maxwaitmillis", "300"));
      int timeout = Integer.parseInt(PropUtil.getProperty("search.redis.timeout", "3000"));
      
      String host = PropUtil.getProperty("search.redis.host", "127.0.0.1");
      int port = Integer.parseInt(PropUtil.getProperty("search.redis.port", "6379"));
      String password = PropUtil.getProperty("search.redis.password", null);
      int database = Integer.parseInt(PropUtil.getProperty("search.redis.database", "0"));
      
      JedisPoolConfig poolConfig = new JedisPoolConfig();
      poolConfig.setMaxTotal(maxTotal);
      poolConfig.setMaxIdle(maxIdle);
      poolConfig.setMaxWaitMillis(maxWaitMillis);
      poolConfig.setTestOnBorrow(false);
      poolConfig.setTestOnReturn(false);
      
      JedisPool pool = new JedisPool(poolConfig, host, port, timeout, password,database);
      customPool = new CustomPool(pool);
    }
  }
  
  public static CustomPool getInstance() {
    return PoolHoledr.customPool;
  }
}
